<template>
    <view style="border-bottom: 2px solid #f2f2f2" class="mb-sm row items-center p-relative card" @click="toDetail(item.id)" >
        <view  style="width: 35vw; max-width: 220rpx; height: 22vw; max-height: 220rpx">
            <image :src="item.avatar" mode="aspectFill" class="fit image" />
            <view class="p-absolute row items-center text-white fs-xs " style="bottom: 10rpx; right: 10rpx; left: 10rpx" v-if="item.status != 1">
                <view class="mx-xs" style="text-shadow: 0rpx 0rpx 2rpx rgb(0, 0, 0)">{{ item.status == 1 ? $t('yifasong') : $t('shenhezhong') }}</view>
                <u-icon name="clock" color="white" size="20rpx"></u-icon>
            </view>
        </view>
        <view class="mx-sm">
            <view class="fs-sm text-nowrap" style="width: 58vw">{{ item.title }}</view>
            <view class="row items-center flex-wrap my-xs">
                <template >
                    <view style="max-width: 66%; width: 70%" class="text-nowrap fs-xs"> {{getposition(item.address)}}</view>
                </template>
            </view>

            <view class="row items-center justify-between mt-xs">
                <view class="row items-center">
                    <view class="fs-sm" style="color: #fc4c38" >{{formatTimeAgo(item.updated_at)}}</view>
                </view>
                <view class="text-gray row items-center" >
                 
                </view>
            </view>
     
            <view class="p-absolute tag" style="bottom: 0rpx; left: 0rpx;">
                {{getTypeList(item._id) + ' '+ $t('infos')}}
            </view>
        </view>
        <!-- 确认删除 -->
       
    </view>
</template>
<script>
export default {
    props: {
        item: {
            type: Object,
            default: () => {},
        },
        type: {
            type: String,
            default: 'maifang',
        },
        action: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            showModal: false,
            directionList: [
                { label: '', val: '' },
                { label: this.$t('dong'), val: 1 },
                { label: this.$t('nan'), val: 2 },
                { label: this.$t('xi'), val: 3 },
                { label: this.$t('bei'), val: 4 },
                { label: this.$t('dongxi'), val: 5 },
                { label: this.$t('nanbei'), val: 6 },
                { label: this.$t('dongnan'), val: 7 },
                { label: this.$t('xinan'), val: 8 },
                { label: this.$t('dongbei'), val: 9 },
                { label: this.$t('xibei'), val: 10 },
            ],
        }
    },
    methods: {
        toDetail(id) {
            uni.navigateTo({
              url: "/pages/info/show?id=" + id,
            })
        },
        getTypeList(id) {
          const lang = uni.getStorageSync("lang") || "ug";
            const typeList = [
                { titleCn: "店铺", title: "دۇكان-ساراي", id: 1 },
                { titleCn: "找工作", title: "خىزمەت", id: 2 },
                { titleCn: "招员工", title: "خىزمەتچىلەر", id: 3 },
                { titleCn: "综合", title: "ئونۋېرسال ", id: 4 },
                { titleCn: "房产", title: "ئۆي-مۈلۈك", id: 5 },
                { titleCn: "车", title: "ماشىنا", id: 6 },
                { titleCn: "出租房", title: "ئىجارە-ئۆي", id: 7 },
                { titleCn: "买卖", title: "سودا-سېتىق", id: 8 },
                { titleCn: "二手", title: "نىمكەش ماللا", id: 9 },
                { titleCn: "农业", title: "يېزا-ئىگىلىك", id: 10 },
                { titleCn: "微商", title: "ئۈندىدار سودا", id: 11 },
                { titleCn: "牲畜", title: "مال-چارۋا", id: 12 },
                { titleCn: "家电", title: "ئېلىكتىر سايمان", id: 13 },
                { titleCn: "园地", title: "باغ ئۇچۇرى", id: 14 },
                { titleCn: "零工", title: "كۈنلۈك ئىش", id: 15 }
            ];
            const type = typeList.find(item => item.id === id);
            return lang === "ug" ? type.title : type.titleCn;
        },
        formatTimeAgo(timestamp) {
            if (!timestamp) return "";

            const now = new Date().getTime();
            const date = new Date(timestamp).getTime();
            const diff = now - date;

            // ۋاقىت پەرقىنى ھېسابلاش
            const minutes = Math.floor(diff / (1000 * 60));
            const hours = Math.floor(diff / (1000 * 60 * 60));
            const days = Math.floor(diff / (1000 * 60 * 60 * 24));
            const months = Math.floor(days / 30);
            const years = Math.floor(days / 365);

            const lang = uni.getStorageSync("lang") || "ug";

            if (minutes < 1) return lang === "ug" ? "ھازىرلا" : "刚刚";
            if (minutes < 60) return lang === "ug" ? `${minutes} مىنۇت بۇرۇن` : `${minutes}分钟前`;
            if (hours < 24) return lang === "ug" ? `${hours} سائەت بۇرۇن` : `${hours}小时前`;
            if (days < 30) return lang === "ug" ? `${days} كۈن بۇرۇن` : `${days}天前`;
            if (months < 12) return lang === "ug" ? `${months} ئاي بۇرۇن` : `${months}月前`;
            return lang === "ug" ? `${years} يىل بۇرۇن` : `${years}年前`;
        },
        getTypeList(id) {
            const typeList = [
                { titleCn: "店铺", title: "دۇكان-ساراي", id: 1 },
                { titleCn: "找工作", title: "خىزمەتلەر", id: 2 },
                { titleCn: "招员工", title: "خىزمەتچىلەر", id: 3 },
                { titleCn: "综合信息", title: "ئونۋېرسال ئۇچۇر", id: 4 },
                { titleCn: "房产", title: "ئۆي-مۈلۈك", id: 5 },
                { titleCn: "车", title: "ماشىنا", id: 6 },
                { titleCn: "出租房", title: "ئىجارە-ئۆي", id: 7 },
                { titleCn: "买卖", title: "سودا-سېتىق", id: 8 },
                { titleCn: "二手", title: "نىمكەش ماللا", id: 9 },
                { titleCn: "农业", title: "يېزا-ئىگىلىك", id: 10 },
                { titleCn: "微商", title: "ئۈندىدار سودىسى", id: 11 },
                { titleCn: "牲畜", title: "مال-چارۋا", id: 12 },
                { titleCn: "家电", title: "ئېلىكتىر سايمان", id: 13 },
                { titleCn: "园地", title: "باغ ئۇچۇرى", id: 14 },
                { titleCn: "零工", title: "ئىشچى", id: 15 }
            ];
            const type = typeList.find(item => item.id === id);
            return type ? type.title : '';
        },
        getposition(value) {
            const positionList = [
                { labelCn: "库尔勒市", label: "كورلا شەھىرى", value: 1 },
                { labelCn: "轮台县", label: "بۈگۈر", value: 2 },
                { labelCn: "尉犁", label: "لوپنۇر", value: 3 },
                { labelCn: "若羌县", label: "چاقىلىق", value: 4 },
                { labelCn: "且末县", label: "چەرچەن", value: 5 },
                { labelCn: "焉耆", label: "قاراشەھەر", value: 6 },
                { labelCn: "和静县", label: "خېجىڭ", value: 7 },
                { labelCn: "和硕县", label: "خوشۇت", value: 8 },
                { labelCn: "博湖", label: "باغراش", value: 9 }
            ];
            const position = positionList.find(item => item.value === value);
            return position ? position.label : '';
        }
    
    },
}
</script>
<style scoped>
.tag {
    background: linear-gradient(#fff6eb,#f99100);
    border-radius: 0 25rpx  0 25rpx ;
    padding: 2rpx 18rpx;
    font-size: 26rpx;
    color: #c94a18;
}
.card{
  background: #fff;
  border-radius: 10rpx;
  box-shadow: 0px 0px 20px 1px #cccccc47;
}
.image{
    border-radius: 25rpx 0 0 25rpx;
}
</style>